
% calculate generators for duration method
clear all
clc

load('D:\My Documents\CIRANO\db_mySQL\tp_2010Dec11_MR7.mat','conditions','numEdges','year_list','durTtlVec','durTtlMat')

transMatGrp = zeros(length(conditions),length(year_list)-1,numEdges,numEdges);
for grp = 1:4
diagInd = logical(eye(numEdges,numEdges));
for yr = 1: length(year_list)-1
totalsVec(:,:) = durTtlVec (grp,yr,1,:);
totalsMat(:,:) = durTtlMat (grp,yr,:,:);
totalsMat(diagInd) = 0;
totalsMat(diagInd) = -sum(totalsMat,2);
nonEmpty = find(totalsVec>0);
transMat(nonEmpty,:) = bsxfun(@ldivide,...
totalsVec(nonEmpty),totalsMat(nonEmpty,:));
transMatGrp(grp,yr,:,:) = transMat;
disp(['Group ' num2str(grp) 'finish'])
end
end

